<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>车辆管理</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">

		<link rel="stylesheet" type="text/css" href="css/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="css/themes/icon.css">
		<link rel="stylesheet" type="text/css" href="js/demo.css">
		<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
		<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
		<link rel="stylesheet" type="text/css" href="css/usedcar.css">
		<style type="text/css">
			#main {
				width: 960px;
			} 
	        #fm{  
	            margin:0;  
	            padding:10px 30px;  
	        }  
	        .ftitle{  
	            font-size:14px;  
	            font-weight:bold;  
	            padding:5px 0;  
	            margin-bottom:10px;  
	            border-bottom:1px solid #ccc;  
	        }  
	        .fitem{  
	            margin-bottom:5px;  
	        }  
	        .fitem label{  
	            display:inline-block;  
	            width:80px;  
	        }
	    </style>
		<script type="text/javascript">
		$(document).ready(function(){
	 		$('#dg').datagrid({ 
				remoteSort : false,
				pageSize: 10,  	
				pageList: [10, 15, 20, 30, 50],
				loadFilter: pagerFilter,
				columns:[[  
				          {field:'vin',title:'车辆识别号',width:80,align:'center', sortable:'true'},  
				          {field:'color',title:'颜色',width:80,align:'center', sortable:'true'},  
				          {field:'plateNum',title:'车牌',width:80,align:'center', sortable:'true'},
				          {field:'money',title:'价格',width:80,align:'center', sortable:'true',
				        	  formatter:function(value,row){
									var str = row.money;
									return str + '万';
				        	  }},
				          {field:'opeTime',title:'购买时间',width:80,align:'center', sortable:'true',
				        	  formatter:function(value,row){
									var str = row.opeTime;
									var m = str.month+1;
									var d = str.date;
									return (str.year+1900)+"-"+(m<10?('0'+m):m)+"-"+(d<10?('0'+d):d);
				        	  }}
				]],
	 			loader: function(param, success, error) {
		 			success(${carMain});
		 		}
	 		}); 
		});
 		function pagerFilter(data){
			if ($.isArray(data)){	// is array
					data = {
						total: data.length,
						rows: data
					}
			}
			var dg = $('#dg');
			var opts = dg.datagrid('options');
			var pager = dg.datagrid('getPager');
			pager.pagination({
				onSelectPage:function(pageNum, pageSize){
					opts.pageNumber = pageNum;
					opts.pageSize = pageSize;
					pager.pagination('refresh',{
						pageNumber:pageNum,
						pageSize:pageSize
					});
					dg.datagrid('loadData',data);
				},
				onRefresh:function(pageNumber, pageSize){
					dg.datagrid('reload');
				}
			});
			if (!data.originalRows){
				data.originalRows = (data.rows);
			}
			var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
			var end = start + parseInt(opts.pageSize);
			data.rows = (data.originalRows.slice(start, end));
			return data;
		}
        //var url;  
        function newUser(){  
            $('#dlg').dialog('open').dialog('setTitle','新建申请单');  
            $('#fm').form('clear');
	        document.getElementById('fm').action="cosmetology/carCosmetologyAction_addApply";  
             
			var date = new Date();
			var y = date.getFullYear();  
			var m = date.getMonth()+1;  
			var d = date.getDate();
			var h = date.getHours();
			var f = date.getMinutes();
			var s = date.getSeconds();
			$('#createDate').val(y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d));
			$('#oddId').val(y+(m<10?('0'+m):m)+(d<10?('0'+d):d)+(h<10?('0'+h):h)+(f<10?('0'+f):f)+(s<10?('0'+s):s)); 
			$('#persontel').numberbox('setValue', ${eauser.tel});
            $('#personemail').val("${eauser.email}");
	        //url = 'cosmetology/carCosmetologyAction_addApply';
        }  
        function editUser(){  
            var row = $('#dg').datagrid('getSelected');  
            if (row){  
                $('#dlg').dialog('open').dialog('setTitle','修改车牌');  
                $('#vin').val(row.vin);
                $('#color').val(row.color);
                $('#plateNum').val(row.plateNum);
                $('#money').val(row.money + '万');
                $('#opeTime').val(formatDate(row.opeTime));
                //url = 'cosmetology/carCosmetologyAction_updateApply?id='+row.oddId;
	        	document.getElementById('fm').action='aasimp/Eauser_updatecarManage?id='+row.vin; 
            }  
        }
        function formatDate(str){
			var m = str.month+1;
			var d = str.date;
        	return (str.year+1900)+"-"+(m<10?('0'+m):m)+"-"+(d<10?('0'+d):d);
        }  
        function saveUser(){
        	if($('#fm').form('validate')){
	            $('#fm').submit();
	            $('#dlg').dialog('close');
        	}   
             
           /* $('#fm').form('submit',{  
                url: url,  
                onSubmit: function(){  
                    return $(this).form('validate');  
                },  
                success: function(result){  
                    var result = eval('('+result+')');
                    if (result.errorMsg){  
                        $.messager.show({  
                            title: 'Error',  
                            msg: result.errorMsg  
                        });  
                    } else {
                        $('#dlg').dialog('close');      // close the dialog  
                        $('#dg').datagrid('reload');    // reload the user data  
                    }  
                }  
            });*/    
        }  
        function destroyUser(){  
            var row = $('#dg').datagrid('getSelected');  
            if (row){  
                $.messager.confirm('提示','确定删除这条记录吗?',function(r){  
                    if (r){
                      	window.location = 'cosmetology/carCosmetologyAction_destroyApply?id='+row.oddId;
                        /*$.post('cosmetology/carCosmetologyAction_destroyApply',{id:row.oddId},function(result){  
                            if (result.success){  
                                $('#dg').datagrid('reload');    // reload the user data  
                            } else {  
                                $.messager.show({   // show error message  
                                    title: 'Error',  
                                    msg: result.errorMsg  
                                });  
                            }  
                        },'json'); */ 
                    }  
                });  
            }  
        }  
		</script>

	</head>

<body>
<div id="main">
	<table id="dg" title="我的车辆" class="easyui-datagrid" style="width:960px;height:364px"  
            toolbar="#toolbar"
            rownumbers="true" fitColumns="true" singleSelect="true">   
    </table>  
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">修改车牌</a>  
    </div>  
      
    <div id="dlg" class="easyui-dialog" style="width:400px;height:350px;padding:10px 20px"  
            closed="true" buttons="#dlg-buttons">  
        <form id="fm" method="post">  
            <table>  
                <tr>  
                    <td>车辆识别号:</td>  
                    <td><input class="easyui-validatebox" type="text" id="vin" name="vin" readonly="readonly"></input></td>  
                </tr>  
                <tr>  
                    <td>颜色:</td>  
                    <td><input class="easyui-validatebox" type="text" id="color" name="color" readonly="readonly"></input></td>  
                </tr>  
                <tr>  
                    <td>车牌:</td>  
                    <td><input class="easyui-validatebox" type="text" id="plateNum" name="plateNum" ></input>
                    </td>  
                </tr>  
                <tr>  
                    <td>价格:</td>  
                    <td><input class="easyui-validatebox" id="money" name="money" readonly="readonly">
				    </td>  
                </tr>  
                <tr>  
                    <td>购买时间:</td>  
                    <td><input class="easyui-validatebox" id="opeTime" name="opeTime" readonly="readonly">
		            </td>  
                </tr> 
            </table>  
        </form>  
    </div>  
    <div id="dlg-buttons">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">Save</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">Cancel</a>  
    </div>  
</div>
</body>
</html>